# @shuaige : 陈世玉
# @name :china_csv.py
# @time :2024/12/8 13:49
import pandas as pd

# 读取文本文件
file_path = 'D:\\python.code\\爬虫学习\\爬虫1\\大学数据\\data1.txt'
with open(file_path, 'r', encoding='utf-8') as file:
    lines = file.readlines()

# 解析数据
data = []
for line in lines:
    parts = line.strip().split()
    data.append(parts)

# 创建 DataFrame
columns = ['排名', '学校名称', '所在省份', '类型', '总分', '办学层次']
df = pd.DataFrame(data, columns=columns)

# 将 DataFrame 保存为 CSV 文件
csv_file_path = 'D:\\python.code\\爬虫学习\\爬虫1\\大学数据\\data1.csv'
df.to_csv(csv_file_path, index=False, encoding='utf-8-sig')

print(f"数据已成功保存到 {csv_file_path}")
